package cate.game.admin.menu.rpc;

import cate.game.common.rpc.RpcSender4Game;
import cp.solution.rpc.path.RpcTestPath;
import cp.solution.rpc.test.TheCat;
import easy.java.struct.ref.IntRef;
import easy.java.util.NumTool;
import lombok.extern.slf4j.Slf4j;

@Slf4j
public class RpcQpsTestTask implements Runnable {

    private String name;
    private RpcSender4Game sender;
    private int times;
    public RpcQpsTestTask(String name, RpcSender4Game sender, int times) {
        this.name = name;
        this.sender = sender;
        this.times = times;
    }

    @Override
    public void run() {
        long beginTime = System.currentTimeMillis();
        int nRecv = 0;
        for(int i = 0; i < times; i++) {
            try {
                TheCat cat = new TheCat();
                cat.name = "小数据.kryo."+i;
                cat.age = NumTool.random(1, 10000_0000);
                IntRef ageCopy = sender.requestResponseCross(RpcTestPath.RR_MANY_SMALL_DATA_KRYO, cat, IntRef.class);
                //log.info("ageCopy={}", ageCopy);
            } catch (Exception e) {
                log.error("", e);
            }
        }
        long costTime = System.currentTimeMillis() - beginTime;
        log.info("{} 耗时 {}ms 每千次耗时 {}ms, nRecv={}", name, costTime, (costTime*1000L/times), nRecv);
    }
}
